<template>
  <t-dialog :visible.sync="visible"
  :header="header"
  confirmBtn="提交"
  :confirmLoading="confirmLoading"
  :onConfirm="submit"
  :onClose="closeDialog"
  :closeOnOverlayClick="false"
  placement="center"
  width="60%">
      <div style="height: 40vh; width: 98%" v-if="!dataLoading">
          <t-form ref="form" :data="formData" :rules="rules" :colon="true">
          <t-row :gutter="[14,25]">
            <t-col :span="6">
                  <t-form-item label="项目名称" name="projectName">
                      <t-input clearable v-model="formData.projectName"></t-input>
                  </t-form-item>
                  <t-form-item label="项目编号" name="projectNum">
                      <t-input clearable v-model="formData.projectNum"></t-input>
                  </t-form-item>
                  <t-form-item label="计划类别" name="projectCategory">
                      <t-input clearable v-model="formData.projectCategory"></t-input>
                  </t-form-item>
                  <t-form-item label="项目类别" name="projectType">
                      <t-input clearable v-model="formData.projectType"></t-input>
                  </t-form-item>
                  <t-form-item label="学科分类" name="subjectClassification">
                      <t-input clearable v-model="formData.subjectClassification"></t-input>
                  </t-form-item>
                  <t-form-item label="申报日期" name="declareDate">
                      <t-input clearable v-model="formData.declareDate"></t-input>
                  </t-form-item>
              </t-col>
              <t-col :span="6">
                  <t-form-item label="关键词" name="keyWord">
                      <t-input clearable v-model="formData.keyWord"></t-input>
                  </t-form-item>
                  <t-form-item label="项目开始日期" name="startDate">
                      <t-input clearable v-model="formData.startDate"></t-input>
                  </t-form-item>
                  <t-form-item label="项目结束日期" name="endDate">
                      <t-input clearable v-model="formData.endDate"></t-input>
                  </t-form-item>
                  <t-form-item label="建议经费总概算" name="adviceFunding">
                      <t-input clearable v-model="formData.adviceFunding"></t-input>
                  </t-form-item>
                  <t-form-item label="申请补助经费" name="subsidyFunding">
                      <t-input clearable v-model="formData.subsidyFunding"></t-input>
                  </t-form-item>
              </t-col>
          </t-row>
      </t-form>
      </div>
  </t-dialog>
</template>

<script>


export default {
  name: "unit-add-edit",
  dicts: ['kpzh_manage_org_code', 'kpzh_national_economy_code', 'kpzh_unit_level', 'kpzh_source_funds'],
  components: {
  },
  props:{
    objId: {
      type: [String, Number],
      default: '',
    },
    header: {
      type: String,
      default: '新增'
    },
    row: {
      type: Object,
      default: () => ({})
    },
    isUpdate: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      visible: true,
      formData: {
        projectName: '',
        projectNum: '',
        projectCategory: '',
        projectType: '',
        subjectClassification: '',
        declareDate: '',
        keyWord: '',
        startDate: '',
        endDate: '',
        adviceFunding: '',
        subsidyFunding: '',
      },
      fileIds: [],
      fileLists: [],
      dataLoading: false,
      locationOptions: [],
      menuOptions: [],
      confirmLoading: false,
      rules: {
        name: [
          { required: true, message: "单位详细名称不能为空" }
        ],
        
      },
      queryParams: {
        pageNum: 1,
        pageSize: 100000,
        name: "",
        status: "",
        dateRange: []
      },
      treeProps: {
        keys: {
          value: 'id'
        },
      }
    }
  },
  created() {
    Object.assign(this.formData, this.row)
    this.getTreeSelect();
    this.getLocation();
    this.getTalents();
  },
  methods: {
    closeDialog() {
      this.$emit("update:visible", false);
    },
    treeChange(value, context) {
      this.formData.orgStats = context.data?.id
    },
    treeClear() {
      this.formData.orgStats = null
    },
    submit() {
      this.confirmLoading = true
      this.$api.kjrc.talentsCredit.add(this.formData).then(res => {
        this.confirmLoading = false
        this.visible = false
        this.$emit("update:visible", false);
        this.$emit("reload")
      }).catch((e) => {
        this.$message.error(e.toString());
        this.confirmLoading = false
      });
    },
    getTreeSelect() {
      this.$api.kpzh.unit.treeSelect().then(response => {
        this.menuOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getLocation(){
      return this.$api.system.location.treeselect().then(response => {
        this.locationOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
  },
}

</script>

<style scoped>

</style>